package windows
{
	import com.bit101.components.Label;
	import flash.display.Sprite;
	import com.bit101.components.RadioButton;
	import flash.events.MouseEvent;
	import property.Align;
	
	/**
	 * Вьюха Align ну шоп выбрать там чо
	 * @author yaempechenki@gmail.com
	 */
	public class AlignView extends Sprite 
	{
		private var align:Align;

		private var titleLabel:Label;
		private var alignRadioButton1:RadioButton;
		private var alignRadioButton2:RadioButton;
		private var alignRadioButton3:RadioButton;
		private var alignRadioButton4:RadioButton;
		private var alignRadioButton5:RadioButton;
		private var alignRadioButton6:RadioButton;
		private var alignRadioButton7:RadioButton;
		private var alignRadioButton8:RadioButton;
		private var alignRadioButton9:RadioButton;
		
		public function AlignView(title:String = "" ) 
		{
			titleLabel = new Label(this, 0, 5, title);
			
			alignRadioButton1 = new RadioButton(this, 0, 20, "", false, onAlignClick);
			alignRadioButton2 = new RadioButton(this, 0, 30, "", false, onAlignClick);
			alignRadioButton3 = new RadioButton(this, 0, 40, "", false, onAlignClick);
			alignRadioButton4 = new RadioButton(this, 10, 20, "", false, onAlignClick);
			alignRadioButton5 = new RadioButton(this, 10, 30, "", false, onAlignClick);
			alignRadioButton6 = new RadioButton(this, 10, 40, "", false, onAlignClick);
			alignRadioButton7 = new RadioButton(this, 20, 20, "", false, onAlignClick);
			alignRadioButton8 = new RadioButton(this, 20, 30, "", false, onAlignClick);
			alignRadioButton9 = new RadioButton(this, 20, 40, "", false, onAlignClick);
		}
		
		private function onAlignClick(event:MouseEvent):void {
			// да похер, раз живем
			if (alignRadioButton1.selected) align = Align.TOP_LEFT;
			if (alignRadioButton2.selected) align = Align.MIDDLE_LEFT;
			if (alignRadioButton3.selected) align = Align.BOTTOM_LEFT;
			if (alignRadioButton4.selected) align = Align.MIDDLE_TOP;
			if (alignRadioButton5.selected) align = Align.MIDDLE;
			if (alignRadioButton6.selected) align = Align.MIDDLE_BOTTOM;
			if (alignRadioButton7.selected) align = Align.TOP_RIGHT;
			if (alignRadioButton8.selected) align = Align.MIDDLE_RIGHT;
			if (alignRadioButton9.selected) align = Align.BOTTOM_RIGHT;
		}
		
		public function getAlign():Align {
			return align;
		}
		
		public function setAlign(align:Align):void {
			this.align = align;
			// да похер, раз живем
			alignRadioButton1.selected = (align == Align.TOP_LEFT);
			alignRadioButton2.selected = (align == Align.MIDDLE_LEFT);
			alignRadioButton3.selected = (align == Align.BOTTOM_LEFT);
			alignRadioButton4.selected = (align == Align.MIDDLE_TOP);
			alignRadioButton5.selected = (align == Align.MIDDLE);
			alignRadioButton6.selected = (align == Align.MIDDLE_BOTTOM);
			alignRadioButton7.selected = (align == Align.TOP_RIGHT);
			alignRadioButton8.selected = (align == Align.MIDDLE_RIGHT);
			alignRadioButton9.selected = (align == Align.BOTTOM_RIGHT);
		}
		
		public function set groupName(name:String):void {
			alignRadioButton1.groupName = name;
			alignRadioButton2.groupName = name;
			alignRadioButton3.groupName = name;
			alignRadioButton4.groupName = name;
			alignRadioButton5.groupName = name;
			alignRadioButton6.groupName = name;
			alignRadioButton7.groupName = name;
			alignRadioButton8.groupName = name;
			alignRadioButton9.groupName = name;
		}
	}
}